<template>
    <view>
        <picker @change="changePickerValue" data-field="industryId" :value="selectedIndex" 
          range-key="name" :range="pickerList">
          <slot></slot>
            <!-- <view class="" v-if="!postDto.industryId">请选择</view>
            <view class="uni-input c6" v-else>{{ industryList[industryIndex].name }}</view> -->
        </picker>
    </view>
</template>
 
<script>
import { Api } from '../../api/api'
import { CustomDict } from './custom_dict'

export default {
    name: "showCommonPicker",
    emits: ['confirm'],
    props: {
        //显示操作菜单
        show: {
            type: Boolean,
            default: false
        },
        currentField: {
            type: String
        },
        currentDto: {
            type: Object,
            default: {}
        }
    },
    created() {
        console.log('commonpicker创建', this.currentField, this.currentDto.industryId)
        Object.assign(this.selectedDto, this.currentDto)
        let that = this
        that.pickerList = CustomDict.parseFieldDictList(this.currentField)
        that.selectedIndex = CustomDict.parseFieldIndex(this.selectedDto, this.currentField, that.pickerList)
    },
    data() {
        return {
            selectedDto: {

            },
            selectedIndex: 0
        }
    },
    methods: {
        changePickerValue(e){
            console.log('commonpicker确认选择', e, this.pickerList)
            let newSelectedDto = {}
            newSelectedDto[this.currentField] = this.pickerList[e.detail.value].value
            newSelectedDto[this.currentField + 'PickerValue'] = this.pickerList[e.detail.value].name
            this.$emit('confirm', newSelectedDto)
        },
    }
}
</script>
 
<style scoped lang="scss">
@import url(../../static/css/base.css);

.tui-actionsheet {
    width: 100%;
    position: fixed;
    left: 0;
    right: 0;
    /* top: 0; */
    z-index: 9999;
    visibility: hidden;
    transform: translate3d(0, 100%, 0);
    transform-origin: center;
    transition: all 0.3s ease-in-out;
    background: #eaeaec;
    background: white;
    min-height: 100rpx;
    /* border-top-left-radius: 32rpx;
    border-top-right-radius: 32rpx; */
    border-radius: 10rpx;

    // background: #333333;

    box-shadow: 0px -4px 4px 0px rgba(0, 0, 0, 0.2);
}

.tui-actionsheet-show {
    transform: translate3d(0, 0, 0);
    visibility: visible;
}

.tui-tips {
    width: 100%;
    padding: 30rpx 60rpx;
    box-sizing: border-box;
    text-align: center;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tui-operate-box {
    padding-bottom: 12rpx;
}

.tui-actionsheet-btn {
    width: 100%;
    height: 100rpx;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 36rpx;
    position: relative;
}

.tui-btn-last {
    padding-bottom: env(safe-area-inset-bottom);
}

.tui-actionsheet-divider::before {
    content: '';
    width: 100%;
    border-top: 1rpx solid #d9d9d9;
    position: absolute;
    top: 0;
    left: 0;
    -webkit-transform: scaleY(0.5);
    transform: scaleY(0.5);
}

.tui-actionsheet-cancel {
    color: #1a1a1a;
    padding-bottom: env(safe-area-inset-bottom);
}

.tui-actionsheet-hover {
    background: #f7f7f9;
}

.tui-actionsheet-mask {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    // background: rgba(0, 0, 0, 0.6);
    background: rgba(0, 0, 0, 0.25);
    z-index: 9996;
    transition: all 0.3s ease-in-out;
    opacity: 0;
    visibility: hidden;
}

.tui-mask-show {
    opacity: 1;
    visibility: visible;
}

.container {
    // top: 546.02px;
    // width: 375px;
    // height: 265.98px;

}

.body-wrap {
    margin-top: 28rpx;

    margin-right: 32rpx;
    font-size: 28rpx;
    font-weight: normal;

    .col-wrap {
        height: 872rpx;
        overflow: scroll;
        border-right: 1px solid rgba(0, 0, 0, 0.12);
        margin-left: 32rpx;

        .title {
            text-align: left;
            margin-bottom: 32rpx;
        }

        .col-item {
            margin-bottom: 56rpx;
            text-align: left;
            color: #666666;
        }

        .col-item-ac {
            font-weight: 600;
            color: rgba(0, 0, 0, 0.85);
        }
    }
}

.btn-wrap {
    // padding-top: 26rpx;
    padding-bottom: 26rpx;
    font-size: 32rpx;
    // border-top: 1px solid rgba(0, 0, 0, 0.12);
    border-top: 1px solid #eee;

    .btn-reset {

        font-weight: normal;

        color: rgba(0, 0, 0, 0.8456);
        text-align: center;
        padding-top: 26rpx;
        padding-bottom: 26rpx;
    }

    .btn-confirm {
        font-weight: 600;
        text-align: center;

        color: rgba(0, 0, 0, 0.85);
        background: #F8D247;
        padding-top: 26rpx;
        padding-bottom: 26rpx;
    }
}</style>